num = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
args = input().split()
check = 0
if len(args) == 3:
    for i in range(len(num)):
        if num[i] == args[0]:
            if i != 0:
                check += 1
                first_digit = i
                for j in range(len(num)):
                    if num[j] == args[1]:
                        check += 1
                        second_digit = j
                        for k in range(len(num)):
                            if num[k] == args[2]:
                                check += 1
                                third_digit = k
if check == 3:
    input_num = first_digit * 100 + second_digit * 10 + third_digit
    simple_nums = []
    prev = 100
    nex = 999
    for p in range(90, 1010):
        for i in range(2, p): 
            if p % i == 0: 
                break 
        else: 
            simple_nums.append(p)
    for l in range(len(simple_nums)):
        if input_num > simple_nums[l]:
            prev = simple_nums[l]
        else:
            nex = simple_nums[l]
            break
    if (input_num - prev) <= (nex - input_num):
        print(prev)
    else:
        print(nex)
else:
    print('Wrong input')